## This file makes all tables pertaining to the simulations

# This file requires "sim/out/performance.rda" to be loaded beforehand

## deterministic
det <- list()
df <- performance_df[[2]]
numVar <- unique(df$J)
for(j in 1:length(numVar)){
  df_j <- subset(df, J==numVar[j], select=c("method", "n", "nrules", "lenrules", "acc"))
  det[[j]] <- reshape(df_j, idvar="n", timevar = "method", direction = "wide")
}
methods <- unique(df_j$method)
header <- c(1, rep(3, times=length(methods)))
names(header) <-  c(" ", methods)
colnames <- c("Num. Rules", "Rule Len.", "Accuracy")

# 5 var
d5 <- kable(round(det[[1]], digits=2), format="latex", booktabs = TRUE, 
      col.names=c("N", rep(colnames, times=length(methods))))%>%
  add_header_above(header=header, escape=F)
write(d5, file="tables/d5_tab.tex")
# 10
rownames(det[[2]]) <- NULL
d10 <- kable(round(det[[2]], digits=2), format="latex", booktabs = TRUE, 
      col.names=c("N", rep(colnames, times=length(methods))))%>%
  add_header_above(header=header, escape=F)
write(d10, file="tables/d10_tab.tex")
# 20
rownames(det[[3]]) <- NULL
d20 <- kable(round(det[[3]], digits=2), format="latex", booktabs = TRUE, 
      col.names=c("N", rep(colnames, times=length(methods))))%>%
  add_header_above(header=header, escape=F)
write(d20, file="tables/d20_tab.tex")



## probabilistic
prob <- list()
df <- performance_df[[1]]
numVar <- unique(df$J)
for(j in 1:length(numVar)){
  df_j <- subset(df, J==numVar[j], select=c("method", "n", "nrules", "lenrules", "acc"))
  prob[[j]] <- reshape(df_j, idvar="n", timevar = "method", direction = "wide")
}
methods <- unique(df_j$method)
header <- c(1, rep(3, times=length(methods)))
names(header) <-  c(" ", methods)
colnames <- c("Num. Rules", "Rule Len.", "Accuracy")

# 5 var
p5 <- kable(round(prob[[1]], digits=2), format="latex", booktabs = TRUE, 
      col.names=c("N", rep(colnames, times=length(methods))))%>%
  add_header_above(header=header, escape=F)
write(p5, file="tables/p5_tab.tex")
# 10
rownames(prob[[2]]) <- NULL
p10 <- kable(round(prob[[2]], digits=2), format="latex", booktabs = TRUE, 
      col.names=c("N", rep(colnames, times=length(methods))))%>%
  add_header_above(header=header, escape=F)
write(p10, file="tables/p10_tab.tex")
# 20
rownames(prob[[3]]) <- NULL
p20 <- kable(round(prob[[3]], digits=2), format="latex", booktabs = TRUE, 
      col.names=c("N", rep(colnames, times=length(methods))))%>%
  add_header_above(header=header, escape=F)
write(p20, file="tables/p20_tab.tex")